﻿Class MainWindow
    Inherits KeyedWindowBase

    Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
        Me.DataContext = New MainWindowVM
    End Sub

    Protected Overrides Sub HandleMessage(sender As KeyedViewModelBase, message As MessageBase)
        Select Case message.GetType
            Case GetType(Messages.MainWindow.Close)
                message.Handled = True
                Me.Close()
            Case GetType(Messages.MainWindow.OpenRawView)
                Dim frm As New RawView(CType(message, Messages.MainWindow.OpenRawView).obj, Me)
                frm.Show()
                message.Handled = True
            Case GetType(Messages.MainWindow.GetRawDirectory)
                Dim m As Messages.MainWindow.GetRawDirectory = CType(message, Messages.MainWindow.GetRawDirectory)
                Dim frm As New RawDirectoryPicker
                frm.Owner = Me
                If frm.ShowDialog.GetValueOrDefault(False) Then
                    m.RawDirectoryPath = frm.ViewModel.RawDirectoryPath
                End If
                message.Handled = True
            Case GetType(Messages.MainWindow.PopoutEditor)
                Dim m As Messages.MainWindow.PopoutEditor = CType(message, Messages.MainWindow.PopoutEditor)
                Dim frm As New PopoutEditorView
                Dim vm As New ObjectEditorVm
                vm.CurrentObject = m.obj
                message.Handled = True
                frm.DataContext = vm
                frm.Show()
        End Select
    End Sub

    Protected Overrides Function GetHandledMessageTypes() As List(Of Type)
        Return New List(Of Type)({GetType(Messages.MainWindow.Close),
                                  GetType(Messages.MainWindow.OpenRawView),
                                  GetType(Messages.MainWindow.GetRawDirectory),
                                  GetType(Messages.MainWindow.PopoutEditor)})
    End Function

    Private Sub CommandBinding_CanExecute(sender As Object, e As CanExecuteRoutedEventArgs)

    End Sub
End Class
